<template>
	<view>
		<view class="form" v-if="is_merchant=='无'">
			<view class="form_item">
				<view class="label">
					我的姓名
				</view>
				<view class="input">
					<u--input placeholder="请输入真实姓名" placeholderStyle='color:#8B8B8B;' border='none'
						v-model="form.realname"></u--input>
				</view>
			</view>
			<view class="form_item">
				<view class="label">
					手机号
				</view>
				<view class="input">
					<u--input placeholder="请输入常用手机号" placeholderStyle='color:#8B8B8B;' border='none'
						v-model="form.phone"></u--input>
				</view>
			</view>
			<view class="form_item">
				<view class="label">
					身份证号
				</view>
				<view class="input">
					<u--input placeholder="请输入本人身份证号" placeholderStyle='color:#8B8B8B;' border='none'
						v-model="form.idcard"></u--input>
				</view>
			</view>
			<view class="form_title">
				<view class="form_line">

				</view>
				<view class="title_name">
					身份证正反面
				</view>
			</view>
			<view class="pic_box">
				<view class="pic_item" v-if="form.faceimage">
					<image class="pic_bg" @click="imgPreview(zsimgs,index)" :src="baseurl+form.faceimage" mode="">
					</image>
					<view class="pic_item_name" style="background-color: rgba(0, 0, 0, 0.5);" @click="up('faceimage')">
						重新上传
					</view>
					<view class="delbox" @click="form.faceimage=''">
						<image class="del_icon" src="/static/img/business/picdel.png" mode=""></image>
					</view>
				</view>
				<view class="pic_item" v-else @click="up('faceimage')">
					<image class="pic_bg" src="/static/img/my/picbg.png" mode=""></image>
					<view class="pic_item_name">
						身份证正面
					</view>
				</view>
				<view class="pic_item" v-if="form.returnimage">
					<image class="pic_bg" @click="imgPreview(zsimgs,index)" :src="baseurl+form.returnimage" mode="">
					</image>
					<view class="pic_item_name" style="background-color: rgba(0, 0, 0, 0.5);"
						@click="up('returnimage')">
						重新上传
					</view>
					<view class="delbox" @click="form.returnimage=''">
						<image class="del_icon" src="/static/img/business/picdel.png" mode=""></image>
					</view>
				</view>
				<view class="pic_item" v-else @click="up('returnimage')">
					<image class="pic_bg" src="/static/img/my/picbg.png" mode=""></image>
					<view class="pic_item_name">
						身份证反面
					</view>
				</view>
			</view>


			<view class="form_title">
				<view class="form_line">

				</view>
				<view class="title_name">
					营业执照
				</view>
			</view>
			<view class="pic_box">
				<view class="pic_item" v-if="form.businessimage">
					<image class="pic_bg" @click="imgPreview(zsimgs,index)" :src="baseurl+form.businessimage" mode="">
					</image>
					<view class="pic_item_name" style="background-color: rgba(0, 0, 0, 0.5);"
						@click="up('businessimage')">
						重新上传
					</view>
					<view class="delbox" @click="form.businessimage=''">
						<image class="del_icon" src="/static/img/business/picdel.png" mode=""></image>
					</view>
				</view>
				<view class="pic_item" v-else @click="up('businessimage')">
					<image class="pic_bg" src="/static/img/my/picbg.png"></image>
					<view class="pic_item_name">
						营业执照
					</view>
				</view>
				<!-- <view class="pic_item">
					<image class="pic_bg" src="/static/img/my/picbg.png" mode=""></image>
					<view class="pic_item_name">
						添加图片
					</view>
				</view> -->
			</view>
			<view class="btn" @click="submit">
				确认提交
			</view>
		</view>
		<view class="" style="margin-top: 100rpx;display: flex;align-items: center;flex-direction: column;font-size: 40rpx;" v-if="is_merchant=='待审核'">
			<image style="width: 200rpx;height: 200rpx;margin-bottom: 20rpx;" src="/static/img/my/examine.png" mode=""></image>
			您提交的申请正在审核中~
		</view>
		<view class="" style="margin-top: 32rpx;display: flex;align-items: center;flex-direction: column;color: #FF6705;font-size: 40rpx;;" v-if="is_merchant=='已关闭'">
			<image style="width: 284rpx;height: 328rpx;margin-bottom: 99rpx;" src="/pages/my/static/err.png" mode=""></image>
			你提交的申请没有通过
			<view class="" style="color: #4D4D4D;font-size: 28rpx;margin-top: 28rpx;">
				详情请联系客服
			</view>
			<view class="relodbtn" @click="is_merchant='无'">
				重新提交申请
			</view>
		</view>
	</view>
</template>

<script>
	import {
		sendRepost
	} from '@/api/my.js'
	export default {
		data() {
			return {
				form: {
					realname: '',
					idcard: "",
					phone: '',
					businessimage: "",
					faceimage: "",
					returnimage: "",
				},
				baseurl: '',
				is_merchant:'',
				
			};
		},
		methods: {
			submit() {
				let {
					realname,
					idcard,
					phone,
					businessimage,
					faceimage,
					returnimage,
				}=this.form
				if(!realname){
					uni.showToast({
						title:'请输入真实姓名',
						icon:'none'
					})
					return
				}
				if(!phone){
					uni.showToast({
						title:'请输入手机号',
						icon:'none'
					})
					return
				}
				if(phone.length!=11){
					uni.showToast({
						title:'请输入正确的手机号',
						icon:'none'
					})
					return
				}
				if(!idcard){
					uni.showToast({
						title:'请输入身份证号',
						icon:'none'
					})
					return
				}
				
				if(!faceimage){
					uni.showToast({
						title:'请上传身份证正面',
						icon:'none'
					})
					return
				}
				if(!returnimage){
					uni.showToast({
						title:'请上传身份证反面',
						icon:'none'
					})
					return
				}
				if(!businessimage){
					uni.showToast({
						title:'请上传营业执照',
						icon:'none'
					})
					return
				}
				sendRepost(this.form).then(res => {
					// console.log(res.data)
					if(res.data.code==1){
						uni.showToast({
							title:'已提交申请，等待审核',
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}
				})
			},
			// 上传
			async up(type) {
				console.log(this.form[type])
				let _this = this
				await uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						// console.log(tempFilePaths)
						tempFilePaths.map(t => {
							uni.showLoading({
								title: '上传中'
							})
							uni.uploadFile({
								url: _this.$BASE_URL +
									'/api/common/upload', //仅为示例，非真实的接口地址
								filePath: t,
								name: 'file',
								header: {
									token: uni.getStorageSync('token')
								},
								success: (uploadFileRes) => {
									this.form[type] = JSON.parse(uploadFileRes.data)
										.data
										.url
									uni.hideLoading()
									uni.showToast({
										title: JSON.parse(uploadFileRes.data)
											.msg,
										icon: 'none'
									})
								},

							});
						})
					}
				});
			},
		},
		onLoad(option) {
			this.baseurl = this.$BASE_URL
			this.is_merchant=option.is_merchant
		}
	}
</script>

<style lang="less">
	.form {
		padding: 10rpx 31rpx 70rpx;
		border-top: 2rpx solid #F4F6F8;

		.form_item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1rpx solid #F4F6F8;
			height: 105rpx;

			.label {
				color: #333;
				font-size: 30rpx;
				font-weight: bold;
				padding-left: 10rpx;
			}

			.input {
				width: 500rpx;
				font-size: 30rpx;
			}
		}

		.form_title {
			display: flex;
			padding: 45rpx 0 36rpx 10rpx;
			align-items: center;
			color: #333;
			font-size: 30rpx;

			.form_line {
				width: 8rpx;
				height: 28rpx;
				background: #FE712A;
				border-radius: 4rpx;
				margin-right: 10rpx;
			}
		}
	}

	.pic_box {
		display: flex;

		.pic_item {
			width: 198rpx;
			height: 198rpx;
			position: relative;
			margin-right: 34rpx;
		}

		.pic_bg {
			width: 198rpx;
			height: 198rpx;
			position: absolute;
			top: 0;
			left: 0;
		}

		.pic_item_name {
			text-align: center;
			width: 100%;
			position: absolute;
			bottom: 0;
			color: #fff;
			font-size: 26rpx;
			line-height: 60rpx;
		}
	}

	.btn {
		width: 687rpx;
		line-height: 114rpx;
		background: linear-gradient(153deg, #FF8717, #FF5F00);
		border-radius: 57rpx;
		text-align: center;
		font-size: 36rpx;
		color: #fff;
		margin-top: 77rpx;
	}

	.delbox {
		width: 29rpx;
		height: 25rpx;
		background: rgba(0, 0, 0, .5);
		border-radius: 7rpx 0 0 12rpx;

		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		top: 0;
		right: 0;
	}

	.del_icon {
		width: 12rpx;
		height: 12rpx;
	}
	.relodbtn{
		width: 391rpx;
		line-height: 90rpx;
		background: linear-gradient(153deg, #FF7E12, #FF6705);
		border-radius: 45rpx;
		color: #FFFFFF;
		font-size: 25rpx;
		text-align: center;
		margin-top: 138rpx;
	}
</style>
